Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 3 op een rij.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <stdio.h>
- #include <iostream>
- #include <string>
- #include <conio.h>
- using namespace std;
- char aanduiding[10]{'0','1','2','3','4','5','6','7','8','9'};
- int kijkwin();
- void bord();
- int keuze;
- string X = "X";
- string O = "O";
- string dilemma;
- int main()
- {
- cout << "Jelmers 3 op een rij\n" << endl;
- cout << "Speler 1, kies je vorm\n1.X\n2.O" << endl;
- int speler = 1, i, keuze;
- speler = (speler % 2) ? 1 : 2;
- char gemarkeerd;
- system("cls");
- do {
- bord();
- cout << "Speler " << speler << ", voer een nummer in"<< endl;
- cin >> keuze;
- gemarkeerd = (speler == 1) ? 'X' : 'O';
- if (keuze == 1 && aanduiding[1] == '1') {
- aanduiding[1] = gemarkeerd;
- }
- else if (keuze == 2 && aanduiding[2] == '2') {
- aanduiding[2] = gemarkeerd;
- }
- else if (keuze == 3 && aanduiding[3] == '3') {
- aanduiding[3] = gemarkeerd;
- }
- else if (keuze == 4 && aanduiding[4] == '4') {
- aanduiding[4] = gemarkeerd;
- }
- else if (keuze == 5 && aanduiding[5] == '5') {
- aanduiding[5] = gemarkeerd;
- }
- else if (keuze == 6 && aanduiding[6] == '6') {
- aanduiding[6] = gemarkeerd;
- }
- else if (keuze == 7 && aanduiding[7] == '7') {
- aanduiding[7] = gemarkeerd;
- }
- else if (keuze == 8 && aanduiding[8] == '8') {
- aanduiding[8] = gemarkeerd;
- }
- else if (keuze == 9 && aanduiding[9] == '9') {
- aanduiding[9] = gemarkeerd;
- }
- else {
- cout << "Deze bitch move is niet toegestaan door de comissie" << endl;
- speler--;
- cin.ignore();
- cin.get();
- }
- i = kijkwin();
- if (speler == 2) {
- speler--;
- }
- else if (speler == 1) {
- speler++;
- }
- } while (i = -1);
- bord();
- if (i == 1) {
- cout << "==>\aSpeler" << --speler << "wint" << endl;
- }
- else {
- cout << "Gelijkspel" << endl;
- cin.ignore();
- cin.get();
- return 0; cout << "\n\n\tDrie op een rij\n\n";
- cout << "Speler 1 (X) - Speler 2 (O)" << endl << endl;
- cout << endl;
- cout << " | | " << endl;
- cout << " " << aanduiding[1] << " | " << aanduiding[2] << " | " << aanduiding[3] << endl;
- cout << "_____|_____|_____" << endl;
- cout << " | | " << endl;
- cout << " " << aanduiding[4] << " | " << aanduiding[5] << " | " << aanduiding[6] << endl;
- cout << "_____|_____|_____" << endl;
- cout << " | | " << endl;
- cout << " " << aanduiding[7] << " | " << aanduiding[8] << " | " << aanduiding[9] << endl;
- cout << " | | " << endl << endl;
- }
- }
- int kijkwin() {
- if (aanduiding[1] == aanduiding[2] && aanduiding[2] == aanduiding[3]) {
- return 1;
- }
- else if (aanduiding[4] == aanduiding[5] && aanduiding[5] == aanduiding[6]) {
- return 1;
- }
- else if (aanduiding[7] == aanduiding[8] && aanduiding[8] == aanduiding[9]) {
- return 1;
- }
- else if (aanduiding[1] == aanduiding[4] && aanduiding[4] == aanduiding[7]) {
- return 1;
- }
- else if (aanduiding[2] == aanduiding[5] && aanduiding[5] == aanduiding[8]) {
- return 1;
- }
- else if (aanduiding[3] == aanduiding[6] && aanduiding[6] == aanduiding[9]) {
- return 1;
- }
- else if (aanduiding[1] == aanduiding[5] && aanduiding[5] == aanduiding[9]) {
- return 1;
- }
- else if (aanduiding[3] == aanduiding[5] && aanduiding[5] == aanduiding[7]) {
- return 1;
- }
- else if (aanduiding[1] != '1' && aanduiding[2] != '2' && aanduiding[3] != '3'
- && aanduiding[4] != '4' && aanduiding[5] != '5' && aanduiding[6] != '6'
- && aanduiding[7] != '7' && aanduiding[8] != '8' && aanduiding[9] != '9'){
- return 0;
- }
- else {
- return -1;
- }
- }
- void bord() {
- system("cls");
- cout << "\n\n\tDrie op een rij\n\n";
- cout << "Speler 1 (X) - Speler 2 (O)" << endl << endl;
- cout << endl;
- cout << " | | " << endl;
- cout << " " << aanduiding[1] << " | " << aanduiding[2] << " | " << aanduiding[3] << endl;
- cout << "_____|_____|_____" << endl;
- cout << " | | " << endl;
- cout << " " << aanduiding[4] << " | " << aanduiding[5] << " | " << aanduiding[6] << endl;
- cout << "_____|_____|_____" << endl;
- cout << " | | " << endl;
- cout << " " << aanduiding[7] << " | " << aanduiding[8] << " | " << aanduiding[9] << endl;
- cout << " | | " << endl << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement