Re:Programozás(c++, php...)

Indította Megax, 2011 október 11, 05:24:09 DÉLUTÁN

Előző téma - Következő téma

Megax

Hello

A jelenlegi példában a "this"-t nem feltétlen kell használni. Ha nem szükséges akkor elhanyagolható. :)
A leírás viszont egész jó lesz. ;)

Skyne

Ide kommenteljetek, ne szemeteljük teli az eredetit, azt lezárom, csak a készítő fogja tudni szerkeszteni, egyébként az ötlet tetszik várjuk a foyltatást ;)

Ryan

Igen azt tudom csak időközben amikor már kitaláltam a példát jónak tartottam ha ezt is megemlítem mert később fontos lehet. :)
Köszönöm örülök h tetszett a leírás hamarosan folyt köv.

Ryan

Annyi kérdésem lenne csak hogy a topikot mikor fogom tudni szerkeszteni? Ugyanis még semmit sem tudok rajta változtatni  :-\

Ryan

Időhiányban nem volt időm folytatni a témát de rövid időn belül majd folytatom a tutoriált a kövi témakörökkel :)
Mindenesetre addig itt az egyik projectem egy rulett játék még nincs kész ezt csak másfél óra aladt tobtam össze és a grafikus megjelenítés is még csak karakteresen van megoldva de a mostani verzioban már lehet rakni a high és low ra. (vannak benne felesleges részek pl a copy construktor de mivel kötprogramnál kötelező h benne legyen igy muszály volt beleraknom) a program még nincs kész de akinek ötletet add saját projectjénak annak itt van:
(player1és player 2 itt nem a töbjátékos mod hanem az egyik europai míg a másik amerikai rulett szisztéma szerint mozog bár az amcsi rulett nincs még kész így azt nme is incluodoltam a rulett.cppbe)

rulett.cpp

#include "player1.h"
//#include "player2.h"
#include <iostream>
//#include "filepath/ui.h"
using namespace std;
int main(){

player1 r;
cout << " _____________________________ "
        << "\n|      ___     |   ___   ___  |" 
        << "\n|     |   |    |  |   | |   | |"
        << "\n|     |   |    |  |   | |   | |"
        << "\n|     |___|    |  |___| |___| |"
        << "\n|              |              |"       
        << "\n|______________|______________|_________ "
        << "\n|         |         |         |         |" 
        << "\n|    1    |    2    |    3    |  *LOW*  |"
        << "\n|         |         |         |         |"
        << "\n|_________|_________|_________|  1 - 18 |"
        << "\n|         |         |         |         |            ________________" 
        << "\n|    4    |    5    |    6    |         |           /   The Wheel.   \\"
        << "\n|         |         |         |         |          /  ______________  \\"
        << "\n|_________|_________|_________|_________|         |  |              |  |"
        << "\n|         |         |         |         |         |  |              |  |" 
        << "\n|    7    |    8    |    9    | *EVEN*  |         |  |______________|  |"
        << "\n|         |         |         |         |         |   ______________   |"
        << "\n|_________|_________|_________|         |         |  |              |  |"
        << "\n|         |         |         |         |         |  |              |  |" 
        << "\n|    10   |    11   |    12   |         |         |  |______________|  |"
        << "\n|         |         |         |         |         |                    |" 
        << "\n|_________|_________|_________|_________|          \\   Total $        /"
        << "\n|         |         |         |         |           \\________________/" 
        << "\n|    13   |    14   |    15   |  *RED*  |"
        << "\n|         |         |         |         |"
        << "\n|_________|_________|_________|         |"
        << "\n|         |         |         |         |" 
        << "\n|    16   |    17   |    18   |         |"
        << "\n|         |         |         |         |"
        << "\n|_________|_________|_________|_________|"
        << "\n|         |         |         |         |" 
        << "\n|    19   |    20   |    21   | *BLACK* |"
        << "\n|         |         |         |         |"
        << "\n|_________|_________|_________|         |"
        << "\n|         |         |         |         |" 
        << "\n|    22   |    23   |    24   |         |"
        << "\n|         |         |         |         |"
        << "\n|_________|_________|_________|_________|"
        << "\n|         |         |         |         |" 
        << "\n|    25   |    26   |    27   |  *ODD*  |"
        << "\n|         |         |         |         |"
        << "\n|_________|_________|_________|         |"
        << "\n|         |         |         |         |" 
        << "\n|    28   |    29   |    30   |         |"
        << "\n|         |         |         |         |"
        << "\n|_________|_________|_________|_________|"
        << "\n|         |         |         |         |" 
        << "\n|    31   |    32   |    33   | *HIGH*  |"
        << "\n|         |         |         |         |"
        << "\n|_________|_________|_________| 19 - 36 |"
        << "\n|         |         |         |         |" 
        << "\n|    34   |    35   |    36   |         |"
        << "\n|         |         |         |         |"
        << "\n|_________|_________|_________|_________|"
        << "\n|   2:1   |   2:1   |   2:1   |"
        << "\n|_________|_________|_________|";
       
int tet;
int a, b, c;
while((r.getszaz()!=0)&&(r.gettiz()!=0)&&(r.getotven()!=0)){
cout<<"/n 10: "<<r.zsetonok[0]<<"50: "<<r.zsetonok[1]<<"100: "<<r.zsetonok[2];
cout<<"/n add meg h mire szeretnel rakni (1 es a low a 2es a high";
cin>>tet;
cout>>"/n mennyit?";
cin>>a;
cin>>b;
cin>>c;
gettet(a,b,c);
r.operator--();
if(r.nyere(tet)==1) {cout<<"/n Nyertel"; r.operator++(); }
else {cout<<"/n vesztettel"; r.nullaz();}

}
}


player1.h

#ifndef player1_h
#define player1_h

class player1{
private:
          int * zsetonok;
          int * tet;
          int a, b, c;
          int m;
public:
      player1();
      ~player1();
      //copy contruktor
      player1(player1&);
      void mentes(int);
      virtual int nyere(int);
      int operator[](int);
      player1& operator++();  //tétnyeréshez
      player1& operator--();  //tetrakáshoz
      void settet(int,int,int);
      void nullaz();
      int getszaz();
      int getotven();
      int gettiz();
      };
     
      #endif



player1.cpp

#include <iostream>
#include<ctime>
#include <fstream>

//saját header includja
#include "player1.h"
using namespace std;


//saját header includja
#include "player1.h"
using namespace std;
player1::player1(){
this->zsetonok = new int[3];
this->tet = new int[3];
this->zsetonok[0] = 100;  // 10es zsetonok
this->zsetonok[1] = 50; //50esek
this->zsetonok[2] = 10; //100asok

this->tet[0] = 0; //itt is ugyanigy
this->tet[1] = 0;
this->tet[2] = 0;
                   }
//copy construktor
player1::player1(player1& p){
this->m = p.m;
this->zsetonok = new int[p.m];
this->tet = new int[p.m];
                          }   
player1::~player1(){
delete[] zsetonok;
delete[] tet;
                    }               
                   
void mentes(){
     }
     
int player1::operator[](int i) {
return this->zsetonok[i];
}
player1& player1::operator++(){
    this->zsetonok[0] += (this->tet[0]*2);
    this->zsetonok[1] += (this->tet[1]*2);
    this->zsetonok[2] += (this->tet[2]*2);
    this->tet[0] = 0;
    this->tet[1] = 0;
    this->tet[2] = 0;
return (*this);
}
player1& player1::operator--(){
    this->zsetonok[0] -= this->a;
    this->zsetonok[1] -= this->b;
    this->zsetonok[2] -= this->b;
    this->tet[0] = a;
    this->tet[1] = b;
    this->tet[2] = c;
return (*this);
}
int player1::nyere(int k){//1 a low a 2 es a high
    int b;
    int num;
    num = rand()%38+0;
    if((num>1)&&(num<18)) {b = 1;}
    else {b = 2;}
   
    if(k==b){return 1;}
     else return 0;
}
void player1::mentes(int c){ //ha 1 akkor betölt ha 2 akkor ment
int f1, f2, f3;
     if(c==1){
     fstream fin("save.txt", fstream::in);
     fin>>this->zsetonok[0];
     fin>>this->zsetonok[1];
     fin>>this->zsetonok[2];
     fin.close();
              }
     else {
     fstream fout("save.txt", fstream::out);
     f1=this->zsetonok[0]; fout<<f1<<"\n";
     f2=this->zsetonok[1]; fout<<f2<<"\n";
     f3=this->zsetonok[2]; fout<<f3<<"\n";
     fout.close();
          }
     }
void player1::settet(int az, int bz, int cz){
     this->a = az;
     this->b = bz;
     this->c = cz;
     }
void player1::nullaz(){
     this->tet[0]=0;
     this->tet[1]=0;
     this->tet[2]=0;
     }
int player1::getszaz(){
      return this->zsetonok[2];
      }
int player1::getotven(){
      return this->zsetonok[1];
      }
int player1::gettiz(){
      return this->zsetonok[0];
      }



player2.h

#ifndef player2_h
#define player2_h
//ez az amerikai rulettet játsza amiben nincs 0-a
class player2 : public player1{
private:
          int * zsetonok;
          int * tet;
          int a, b, c;
public:
      player2();
      ~player2();
      int nyere(int);
     
      };
#endif



player2.cpp

#include <iostream>
#include<ctime>

//saját header includja
#include "player2.h"
//#include "player1.h"
using namespace std;
player2::player2(){
this->zsetonok = new int[3];
this->tet = new int[3];
this->zsetonok[0] = 100;  // 10es zsetonok
this->zsetonok[1] = 50; //50esek
this->zsetonok[2] = 10; //100asok

this->tet[0] = 0; //itt is ugyanigy
this->tet[1] = 0;
this->tet[2] = 0;
                   }
player2::~player2(){
delete[] this->zsetonok;
delete[] this->tet; }

int player2::nyere(int k){//1 a low a 2 es a high
    int b;
    int num;
    num = rand()%38+1;
    if((num>1)&&(num<18)) {b = 1;}
    else if((num>19)&&(num<38)) {b = 2;}
    else {b = 3;}
   
    if(k==b){return 1;}
     else return 0;
}


Powered by EzPortal